Skip to content

Conversation

@carlosdelest
Copy link
Member

Refactors tests on VerifierTests to include all full text functions

@carlosdelest carlosdelest added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch >test Issues or PRs that are addressing/adding tests auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 and removed v9.1.0 labels Jun 2, 2025
plan,
condition,
Term.class,
FullTextFunction.class,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified this to just run on all FullTextFunctions

return fields.stream()
.map(
(Expression field) -> isNotNull(field, sourceText(), FIRST).and(
(Expression field) -> isNotNull(field, sourceText(), SECOND).and(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed a bug in MultiMatch when refactoring the tests

@carlosdelest carlosdelest marked this pull request as ready for review June 2, 2025 16:07
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine removed the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jun 2, 2025
+ " or first_name is not null) or (length(first_name) > 12 and match(last_name, \"Smith\"))"
);
query("from test | where " + functionInvocation + " or (last_name is not null and first_name is null)");
if ("KQL".equals(functionName) || "QSTR".equals(functionName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this test need to be limited to just KQL and QSTR? I'd expect the same error for match too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's limited to QSTR / KQL, as these do not include a field. MATCH et al would fail on not having an actual field to look into, as this test case uses ROW to generate a column instead.

"1:45: [QSTR] function cannot be used after RENAME",
error("from test | rename last_name as full_name | where qstr(\"Anna\")")
);
public void testNonFieldBasedFullTextFunctionsNotAllowedAfterCommands(String functionName, String functionInvocation) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these helper methods be private?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Done in ac0982a

"1:48: [MATCH] function cannot operate on [text::keyword], which is not a field from an index mapping",
error("row n = null | eval text = n + 5 | where match(text::keyword, \"Anna\")")
);
public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we group this one with the KQL equivalent in one function? so we keep the same pattern that we have in the rest of the file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done in ac0982a

assertEquals(
"1:67: [MATCH] function cannot operate on [initial], which is not a field from an index mapping",
error("from test | eval initial = substring(first_name, 1) | where match(initial, \"A\")")
public void testFieldBasedWithNonIndexedColumn(String functionName, String functionInvocation, String functionType) {
Copy link
Contributor

@ioanatia ioanatia Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have a different name pattern for these helper functions e.g. checkFieldBasedWithNonIndexedColumn.
we have other functions like this e.g. checkFullTextFunctionsOnlyAllowedInWhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I have been inconsistent here. Done in ac0982a

Copy link
Member Author

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review @ioanatia ! I've fixed the inconsistent naming you found.

+ " or first_name is not null) or (length(first_name) > 12 and match(last_name, \"Smith\"))"
);
query("from test | where " + functionInvocation + " or (last_name is not null and first_name is null)");
if ("KQL".equals(functionName) || "QSTR".equals(functionName)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's limited to QSTR / KQL, as these do not include a field. MATCH et al would fail on not having an actual field to look into, as this test case uses ROW to generate a column instead.

"1:45: [QSTR] function cannot be used after RENAME",
error("from test | rename last_name as full_name | where qstr(\"Anna\")")
);
public void testNonFieldBasedFullTextFunctionsNotAllowedAfterCommands(String functionName, String functionInvocation) throws Exception {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Done in ac0982a

"1:48: [MATCH] function cannot operate on [text::keyword], which is not a field from an index mapping",
error("row n = null | eval text = n + 5 | where match(text::keyword, \"Anna\")")
);
public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done in ac0982a

assertEquals(
"1:67: [MATCH] function cannot operate on [initial], which is not a field from an index mapping",
error("from test | eval initial = substring(first_name, 1) | where match(initial, \"A\")")
public void testFieldBasedWithNonIndexedColumn(String functionName, String functionInvocation, String functionType) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I have been inconsistent here. Done in ac0982a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this new mapping, as I found easier when working on KNN to have a separate mapping for full text functions than to modify the default mapping - which impacted a lot of other tests.

This way we can be the owners of this mapping in case we want to add later for example sparse_vector field types, and not impact other test cases.

@carlosdelest carlosdelest requested a review from ioanatia June 3, 2025 10:20
Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good - left 2 nitpicky comments which can be addressed without requesting another review.
I do want to callout that this will generate merge conflicts with #127661 which should be fine, just letting @kderusso know

"1:36: [MultiMatch] function is only supported in WHERE and STATS commands\n"
+ "line 1:55: [MultiMatch] function cannot operate on [title], which is not a field from an index mapping",
error("row title = \"brown fox\" | eval x = multi_match(\"fox\", title)")
private void testFullTextFunctionsConstantQuery(String functionInvocation, String argOrdinal) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be checkFullTextFunctionsConstantQuery 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - did that on 2818298

assertEquals(
"1:19: first argument of [multi_match(null, first_name)] cannot be null, received [null]",
error("from test | where multi_match(null, first_name)")
private void testFullTextFunctionNullArgs(String functionInvocation, String argOrdinal) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be checkFullTextFunctionNullArgs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch - did that on 2818298

@carlosdelest carlosdelest enabled auto-merge (squash) June 3, 2025 10:52
@carlosdelest carlosdelest merged commit dc3d515 into elastic:main Jun 3, 2025
17 of 18 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 128775

@carlosdelest
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

carlosdelest added a commit to carlosdelest/elasticsearch that referenced this pull request Jun 3, 2025
(cherry picked from commit dc3d515)

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MultiMatch.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java
joshua-adams-1 pushed a commit to joshua-adams-1/elasticsearch that referenced this pull request Jun 3, 2025
carlosdelest added a commit that referenced this pull request Jun 3, 2025
(cherry picked from commit dc3d515)

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MultiMatch.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java
Samiul-TheSoccerFan pushed a commit to Samiul-TheSoccerFan/elasticsearch that referenced this pull request Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged backport pending Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) >test Issues or PRs that are addressing/adding tests v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants